package com.hbnu.test.www.net;

import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;

public class TCP_client01 {
    public static void main(String[] args) {
        //1.创建客户端socket,需要指定服务器端ip和端口
        try (Socket socket = new Socket("127.0.0.1", 6666)) {
            //2.准备发送的数据，获取流资源进行数据交互
            byte[] bytes = "我是张扬".getBytes();
            OutputStream outputStream = socket.getOutputStream();
            //3.通过输入输出流进行数据交互操作
            outputStream.write(bytes);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        //4.关闭流资源与socket资源(自动执行了)
    }
}
